<?php
// +----------------------------------------------------------------------
// | EtrolPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Author: Author: HCZ <huangchengze@etrol.com>
// +----------------------------------------------------------------------

namespace app\basic\controller;

use app\common\controller\Admin;
use app\basic\controller\api\Staff as StaffApi;
use app\admin\controller\ajax\Library as LibraryAjax;
/**
 * 企业管理
 * @package app\enterprise
 */
class Staff  extends Admin

{

	protected $api;
	protected $property;

	public function _initialize()
	{
		parent::_initialize();
		$this->api = new StaffApi();
		$this->property = new LibraryAjax();
	}
	/**
	 * 首页
	 *
	 */
	public function index() {
		if(IS_AJAX){
			$staffList = $this->api->staffList($this->scope);
			return $staffList;
		}
		$enterpriseList = model('Enterprise')->getSelectList($this->scope);
		$this->assign('enterpriseList',$enterpriseList);
		return $this->fetch();
	}

	/**
	 * 查询
	 */
	public function search() {
		if(IS_AJAX){
			$staffList = $this->api->search(input('keyword'),input('enterpriseId'));
			return $staffList;
		}
	}
	/**
	 * 添加企业
	 *
	 */
	public function add() {
		if(IS_POST){
			$data = input('post.');
			if(isset($data['isValid'])){
				$data['isValid'] = 1;
			}else{
				$data['isValid'] = 0;
			}

			if(isset($data['safetyTraining'])){
				$data['safetyTraining'] = 1;
			}else{
				$data['safetyTraining'] = 0;
			}
			if(isset($data['securityCertificate'])){
				$data['securityCertificate'] = 1;
			}else{
				$data['securityCertificate'] = 0;
			}
			return $this->api->add($data);
		}
		//企业列表
		$enterpriseList = model('Enterprise')->getSelectList($this->scope);
		$this->assign('enterpriseList',$enterpriseList);
		//部门列表
		$departmentList = $this->property->getDepartmentType()->getData();
		$this->assign('departmentList',$departmentList);
		//职位列表
		$postList = $this->property->getPostType()->getData();
		$this->assign('postList',$postList);
		//文凭列表
		$educationList = $this->property->getEducationType()->getData();
		$this->assign('educationList',$educationList);
		return $this->fetch();
	}

	/**
	 * 修改企业
	 *
	 */
	public function edit($staffId = null) {
		if(IS_POST){
			$data = input('post.');
			if(isset($data['isValid'])){
				$data['isValid'] = 1;
			}else{
				$data['isValid'] = 0;
			}
			if(isset($data['securityCertificate'])){
				$data['securityCertificate'] = 1;
			}else{
				$data['securityCertificate'] = 0;
			}
			if(isset($data['safetyTraining'])){
				$data['safetyTraining'] = 1;
			}else{
				$data['safetyTraining'] = 0;
			}
			
			return $this->api->edit($data,$staffId);
		}
			//企业列表
		$enterpriseList = model('Enterprise')->getSelectList($this->scope);
		$this->assign('enterpriseList',$enterpriseList);
		//部门列表
		$departmentList = $this->property->getDepartmentType()->getData();
		$this->assign('departmentList',$departmentList);
		//职位列表
		$postList = $this->property->getPostType()->getData();
		$this->assign('postList',$postList);
		//文凭列表
		$educationList = $this->property->getEducationType()->getData();
		$this->assign('educationList',$educationList);
		//员工信息
		$staff = model('Staff')->find($staffId);
		$this->assign('info',$staff);
		return $this->fetch();
	}

	/**
	 * 删除企业
	 */
	public function del() {
		if(IS_AJAX){
			return $this->api->del(input('staffId'));
		}
	}



}